package com.aaa.market.controller;

import com.aaa.common.constants.ExceptionConstant;
import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.Result;
import com.aaa.market.entity.AdvertisePosition;
import com.aaa.market.service.AdvertisePositionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 广告位位置(AdvertisePosition)表控制层
 *
 * @author makejava
 * @since 2020-11-17 19:04:37
 */
@RestController
@RequestMapping("advertisePosition")
public class AdvertisePositionController {
    /**
     * 服务对象
     */
    @Resource
    private AdvertisePositionService advertisePositionService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public AdvertisePosition selectOne(Object id) {
        return this.advertisePositionService.queryById(id);
    }




    /**
     * 新增
     */
    @PostMapping("insertAdvertisePosition")
    public Result insertAdvertisePosition(@RequestBody AdvertisePosition advertisePosition){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),advertisePositionService.insert(advertisePosition));
    }


    /**
     * 修改
     */
    @PutMapping("updateAdvertisePosition")
    public Result updateAdvertisePosition(@RequestBody AdvertisePosition advertisePosition){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),advertisePositionService.update(advertisePosition));
    }


    @DeleteMapping("deleteAdvertisePosition")
    public Result deleteAdvertisePosition(Integer id){
        //当ID为空时抛出自定义异常
        if (null==id){
            throw new CustomException(ExceptionConstant.ID_NOT_NULL.getErrorCode(),
                    ExceptionConstant.ID_NOT_NULL.getErrorMessage());
        }
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.advertisePositionService.deleteById(id));
    }

    /**
     * 分页模糊查询
     * @param pageNo
     * @param pageSize
     * @param advertisePosition
     * @return
     */
    @GetMapping("queryAllByParam")
    public Result queryAllByParam(Integer pageNo, Integer pageSize, AdvertisePosition advertisePosition){
        return advertisePositionService.queryAll(pageNo,pageSize,advertisePosition);
    }
}